package com.affablebeans.model;

import javax.sql.DataSource;

import com.affablebeans.model.repository.Categories;
import com.affablebeans.model.repository.Customers;
import com.affablebeans.model.repository.OrderedProducts;
import com.affablebeans.model.repository.Orders;
import com.affablebeans.model.repository.Products;

/**
 *
 * @author Bora SAYINER
 * @since Jan 25, 2015 6:02:55 PM
 * @version 1.0
 */
public class DbContext {

	private Categories categories;
	private Customers customers;
	private Orders orders;
	private Products products;
	private OrderedProducts orderedProducts;

	private final DataSource dataSource;

	public DbContext(DataSource dataSource) {
		this.dataSource = dataSource;
	}

	public Categories getCategories() {
		if (categories == null) categories = new Categories(dataSource);
		return categories;
	}

	public Customers getCustomers() {
		if (customers == null) customers = new Customers(dataSource);
		return customers;
	}

	public Orders getOrders() {
		if (orders == null) orders = new Orders(dataSource);
		return orders;
	}

	public Products getProducts() {
		if (products == null) products = new Products(dataSource);
		return products;
	}

	public OrderedProducts getOrderedProducts() {
		if (orderedProducts == null) orderedProducts = new OrderedProducts(dataSource);
		return orderedProducts;
	}
}
